/**
 *
 */
package cn.sciento.farm.devicemanager.common.exception;

import org.apache.commons.lang3.StringUtils;

import java.util.Map;

import static cn.sciento.farm.devicemanager.common.constant.ResultConstant.INTERNAL_ERROR;


/**
 * @author ShenHuaJie
 * @version 2016年6月7日 下午8:43:02
 */
@SuppressWarnings("serial")
public  class BaseException extends RuntimeException {
    public BaseException() {
    }

    public BaseException(Throwable ex) {
        super(ex);
    }

    public BaseException(String message) {
        super(message);
    }

    public BaseException(String message, Throwable ex) {
        super(message, ex);
    }

    public void handler(Map<String,Object> modelMap) {
        modelMap.put("code", getCode());
        if (StringUtils.isNotBlank(getMessage())) {
            modelMap.put("msg", getMessage());
        } else {
            modelMap.put("msg", getMessage());
        }
        modelMap.put("timestamp", System.currentTimeMillis());
    }

    public   int getCode(){
        return INTERNAL_ERROR.getCode();
    }
}
